<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>喜只猫管理系统</title>
<!-- Tell the browser to be responsive to screen width -->
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">

<#include "../common/header.html">

</head>
<body class="hold-transition skin-blue sidebar-mini">
	<OBJECT id="myActivex"
		classid="clsid:46059496-E96D-45D7-9DB4-2240411F1AF1"
		codebase="/embed/gzyct_ytp.cab#version=1,0,0,10" width="0" height="0"></OBJECT>
	<div class="wrapper">

		<!-- 	顶部和左侧菜单的jsp s -->
		<#include "../common/menu.html">
		<!-- 	顶部和左侧菜单的jsp e -->

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>添加菜单信息</h1>
			</section>



			<!-- Main content -->
			<section class="content" style="padding-bottom: 0px;" id="content">
				<!-- general form elements -->
				<div class="box box-primary" style="width: 1000px; margin: 0 auto;">
					<div class="box-header with-border">
						<h3 class="box-title">菜单信息</h3>
					</div>
					<!-- /.box-header -->
					<!-- form start -->
					<form role="form" action="/cloudpay/menu/addAction" method="post"
						id="conditionForm">
						<div class="box-body">
							<div class="form-group">
								<label for="parentId">请选择菜单目录</label> 
									<select class="form-control select2" style="width: 100%;" name="parendId" id="parendId">
										<option selected="selected"  value="-1">根目录</option>
										<#list menuList as menu>
											<#if menu.parentId gt 0>
												<option value="${menu.id}" >${menu.parentId}-${menu.id} ${menu.name}</option> <#else>
												<option value="${menu.id}" >${menu.id} ${menu.name}</option>
											</#if>
										</#list>
								</select>
							</div>
							<div class="form-group">
								<label for="name">菜单名称</label> 
								<input type="text" class="form-control" id="name" name="name">
							</div>
							<div class="form-group">
								<label for="type">类型</label> 
								<select class="form-control select2" style="width: 100%;" name="type" id="type">
									<#list typeMap?keys as key>
										<option value="${key}">${typeMap[key]!}</option> 
									</#list>
								</select>
							</div>
							<div class="form-group">
								<label for="orderNum">排序</label> 
									<input type="text" class="form-control" id="orderNum" name="orderNum">
							</div>
							<div class="form-group">
								<label for="url">连接</label> <input type="text" class="form-control" id="url" name="url">
							</div>
						</div>
						<!-- /.box-body  @click="submit"-->
						<div class="box-footer">
							<label class="control-label" id="errorLabel" for="inputError" style="color: #dd4b39; width: 370px; max-width: 500px"></label><br />
							<button type="button" class="btn btn-primary" @click="submit">提交</button>
							<button type="button" class="btn btn-primary" @click="back">返回</button>
						</div>
					</form>
				</div>
				<!-- /.box -->
			</section>
			<!-- /.content -->
		</div>

	</div>
	<!-- ./wrapper -->
</body>
<script>


//var adminMenu = JSON.parse($("#adminMenu").val());


$(function () {
	var vm = new Vue(
			{
				el : '#content',
				methods : {
 					back : function(){
						history.back(-1);
					},
					
					submit : function(){
						if(validForm().form() == false)
						{
							return;
						}
						var parendId = $("#parendId").val();
						var name = $("#name").val();
						var type = $("#type").val();
						var orderNum = $("#orderNum").val();
						var url = $("#url").val();
					    $.ajax({
					         url: '/cloudpay/menu/addAction',    
					         type: 'POST',
					         data: {parendId: parendId, name : name, type : type, orderNum : orderNum, url : url },
					         success: function (result) {    
					             var resultObj = JSON.parse(result);
					             if(resultObj.result_code == '0')
					           	 {
					            	alert("添加菜单成功");
									$("#parendId").val("");
									$("#name").val("");
									$("#type").val("");
									$("#orderNum").val("");
									$("#url").val("");
					           	 }
					             else
					             {
					            	 $("#errorLabel").html(resultObj.err_msg);
					             }
					         },
					         error: function (result) {    
					             alert("绑定请求失败 = " + JSON.stringify(result));    
					         }    
					    }); 
					}
				}
			})
	
 	function validForm(){
		return $("#conditionForm").validate(
				{
					onkeyup : false,
					focusInvalid : false,  //错误时,错误选项不会得到焦点
					focusCleanup : true,   //得到焦点时，清空错误提示信息
					submitHandler : function() { //表单提交句柄,为一回调函数，带一个参数：form
						vm.submitForm();
					},
					rules : {						
						name : {
							required:true,
							maxlength:16,
						},
						type : {
							required:true
						}
					},
					messages : {
						name : {
							required:"菜单名称不能为空",
							maxlength:"菜单名称不大于16位",
						},
						type : {
							required:"类型为必选"
						}
					}
				});
	}
	$(validForm());
});
</script>

<script src="${resurcePath}/cloudpay/js/common/dataTable.js"></script>

</html>